package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.GetUserInfoVO;
import com.luo.model.ResultObj;
import com.luo.model.User;
import com.luo.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/2/18 20:40
 */
@WebServlet("/updateUserInfo")
public class UpdateUserInfoController extends HttpServlet {

    UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("userName");
        String status = req.getParameter("status");
        String sex = req.getParameter("sex");
        String revision = req.getParameter("revision");
        String phone = req.getParameter("phone");
        String password = req.getParameter("password");
        String nickName = req.getParameter("nickName");
        String img = req.getParameter("img");
        String birthday = req.getParameter("birthday");
        String age = req.getParameter("age");
        String id = req.getParameter("id");
        GetUserInfoVO user = new GetUserInfoVO();
        user.setId(Integer.valueOf(id));
        user.setUserName(name);
        user.setAge(age);
        user.setStatus(status);
        user.setSex(sex);
        user.setRevision(revision);
        user.setPhone(phone);
        user.setPassword(password);
        user.setImg(img);
        user.setBirthday(birthday);
        user.setNickName(nickName);
        int i = userService.updateUserInfo(user);
        ResultObj result = new ResultObj();
        if (i > 0){
            result.setCode("1");
            result.setMsg("修改成功");
        }else{
            result.setCode("-1");
            result.setMsg("修改失败");
        }
        String jsonString = JSON.toJSONString(result);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
